package com.cy.study.common;

import com.cy.study.exception.BusinessException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 * @version v1.0.0
 * @explain
 * @date 2024/3/25 20:17
 */
@ControllerAdvice
@Validated
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Response handleValidationExceptions(BusinessException ex) {
        return Response.serverError(ex.getMsg());
    }


//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public Response handleExceptions(Exception ex) {
//        return Response.serverError("系统未知异常");
//    }

}
